<?php

/*
 * 后台首页
 */
class Welcome extends Admin_Controller {
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function index()
	{
		$this->display('welcome.tpl');
	}
	
	public function top()
	{
		$this->display('top.tpl');
	}
	
	public function left()
	{
		$this->display('left.tpl');
	}
	
	public function right()
	{
		$this->display('right.tpl');
	}

	public function verify()
	{
		$this->load->library('image');
		$config = array(
			'name' => 'admin_verify',
			'line' => 0
		);
		$this->image->verify($config);
	}

	public function login()
	{
		if (is_get())
		{
			$this->display('login.tpl');
		}
		else
		{
			$this->login_check();
		}
	}
	
	private function login_check()
	{
		$username = post('username');
		$password = post('password');
		$verify = post('verify');
		
		if ($username=='')
		{
			exit('请输入用户');
		}
		if ($password=='')
		{
			exit('请输入密码');
		}
		if ($verify=='')
		{
			exit('请输入验证码');
		}
		
		if (md5($verify)!==get_session('admin_verify'))
		{
			exit('验证码错误');
		}
		
		//销毁验证码session数据
		destroy_session('admin_code');
		
		$this->load->library('sauth');
		if (FALSE===$this->sauth->login($username, $password))
		{
			exit($this->sauth->error());
		}
	}
	
	public function logout()
	{
		$this->load->library('sauth');
		$this->sauth->logout();
		msg('成功退出系统', admin_url('welcome/login'));
	}
	
}